package
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.*;
	import flash.utils.getQualifiedClassName;
	
	/** Displays set of tools that user may select to act upon drawing panel */
	public class ToolMenu extends Sprite
	{
		// constants
		public static const POINT_COLOR:uint = 0xAA8844;
		public static const BACKGROUND_COLOR:uint = 0xCC6666;
		public static const DEFAULT_TEXT_COLOR:uint = 0x4444AA;
		public static const TOOL_OUTLINE_COLOR:uint = 0x000000;
		public static const X_PADDING:int = 8, Y_PADDING:int = 4;
		public var WIDTH:int = 192; // 4 + 90 + 4 + 90 + 4
		public var HEIGHT:int;
		public var TITLE_HEIGHT:int = 46;
		public var BUTTON_WIDTH:int = 80;
				
		// private objects
		private var hideArray:Array;
		// buttons
		private var toolBack:Sprite, gameBack:Sprite, firstb:Sprite, undob:Sprite, redob:Sprite, lastb:Sprite, penb:Sprite, dragb:Sprite, pinb:Sprite, deleteb:Sprite, parallelb:Sprite, lengthb:Sprite, angleb:Sprite, rightb:Sprite; 
		private var hide_pen:Boolean=false, hide_drag:Boolean=false, hide_pin:Boolean=false, hide_delete:Boolean=false, hide_parallel:Boolean=false, hide_length:Boolean=false, hide_angle:Boolean=false, hide_right:Boolean=false; 
		private var selectedButton:Sprite;
		private var selectedOutline:Shape, overOutline:Shape;
		// textfields
		private var toolTField:TextField,gameTField:TextField, pointsTField:TextField,segmentsTField:TextField,anglesTField:TextField, firstTField:TextField, undoTField:TextField, lastTField:TextField, redoTField:TextField, penTField:TextField, dragTField:TextField, pinTField:TextField, deleteTField:TextField, parallelTField:TextField, lengthTField:TextField, angleTField:TextField, rightTField:TextField; 
		private var freePointsTField:TextField;
		private var modeName:String="";
		// private vars
		private var enabled:Boolean;
		private var _freePointsRemaining:int;
		public function get freePointsRemaining():int{return _freePointsRemaining;}
		public function set freePointsRemaining(c:int):void{if (_freePointsRemaining>=0){_freePointsRemaining=c; if(!hide_pen)drawPenButton();}}
		public function enable():void{enabled=true;}
		public function disable():void{enabled=false;}
		
		public function ToolMenu(WIDTH:Number, HEIGHT:Number, freePoints:int=-1, hideArray:Array=null)
		{
			this.WIDTH = WIDTH;
			this.HEIGHT = HEIGHT;
			this.BUTTON_WIDTH = (WIDTH - 3*X_PADDING)/2;
			this.TITLE_HEIGHT = HEIGHT/15;
			enable();
			_freePointsRemaining = freePoints;
			this.hideArray = hideArray;
			this.addEventListener(Event.ADDED, handleAdded);
		}
		private function handleAdded(event:Event):void
		{
			this.removeEventListener(Event.ADDED, handleAdded);
			
			// draw some background color
			this.graphics.lineStyle(1, 0x444444);
			this.graphics.beginFill(0xFFEEEE);
			this.graphics.drawRect(0,0,WIDTH, this.parent.height);
			this.graphics.endFill();
			// title background
			toolBack = new Sprite();
			toolBack.graphics.lineStyle(1,0x000000);
			toolBack.graphics.beginFill(BACKGROUND_COLOR);
			toolBack.graphics.drawRect(0,0,WIDTH, TITLE_HEIGHT);
			toolBack.graphics.endFill();
			this.addChild(toolBack);
			
			// draw title
			toolTField = new TextField ();
			toolTField.mouseEnabled = false;
			toolTField.selectable = false;
			toolTField.defaultTextFormat = new TextFormat ("arial", 22, 0xFFFFFF, null, null, null, null, null, "center");
			toolTField.text = "Tools";
			toolTField.autoSize = "center";
			toolTField.width = WIDTH/2;
			toolTField.x = 10;
			toolTField.y = 0;
			toolBack.addChild(toolTField);			
			
			gameBack = new Sprite();
			gameBack.graphics.lineStyle(1,0x000000);
			gameBack.graphics.beginFill(0x6666AA);
			gameBack.graphics.drawRect(0,0,WIDTH/2, TITLE_HEIGHT*2/3);
			gameBack.graphics.endFill();
			gameBack.x = WIDTH/2;
			gameBack.addEventListener(MouseEvent.MOUSE_OVER, handleMouseOverGame);
			this.addChild(gameBack);
									
			gameTField = new TextField ();
			gameTField.mouseEnabled = false;
			gameTField.selectable = false;
			gameTField.defaultTextFormat = new TextFormat ("arial", 22, 0xAAAAAA, null, null, null, null, null, "center");
			gameTField.text = "Shapes";
			gameTField.autoSize = "center";
			gameTField.width = WIDTH/2;
			gameTField.x = 10;
			gameTField.y = 0;
			gameBack.addChild(gameTField);
			
			// draw first, undo, redo, last
			drawFirstButton();
			firstb.x = X_PADDING;
			firstb.y = toolBack.y + toolBack.height + Y_PADDING;
			
			drawUndoButton();
			undob.x = firstb.x + firstb.width + X_PADDING;
			undob.y = toolBack.y + toolBack.height + Y_PADDING;
			undoTField = new TextField();
			undoTField.selectable = false;
			undoTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
			undoTField.text = "undo";
			undoTField.autoSize = "left";
			undoTField.x = undob.x + (undob.width - undoTField.width)/2;
			undoTField.y = undob.y + undob.height;// + PADDING;
			this.addChild(undoTField);
						
			drawLastButton();
			lastb.x = WIDTH - lastb.width - X_PADDING;
			lastb.y = toolBack.y + toolBack.height + Y_PADDING;
			
			drawRedoButton();
			redob.x = lastb.x - redob.width - X_PADDING;
			redob.y = toolBack.y + toolBack.height + Y_PADDING;
			redoTField = new TextField();
			redoTField.selectable = false;
			redoTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
			redoTField.text = "redo";
			redoTField.autoSize = "left";
			redoTField.x = redob.x + (redob.width - redoTField.width)/2;
			redoTField.y = redob.y + redob.height;// + PADDING;
			this.addChild(redoTField);			
			
			// what buttons are being hidden?
			if (hideArray != null)
			{
				for each (var hs:String in hideArray)
				{
					switch (hs)
					{
						case "pen": hide_pen = true; break;
						case "drag": hide_drag = true; break;
						case "pin": hide_pin = true; break;
						case "delete": hide_delete = true; break;
						case "parallel": hide_parallel = true; break;
						case "length": hide_length = true; break;
						case "angle": hide_angle = true; break;
						case "right": hide_right = true; break;
					}
				}
			}
			
			// draw a line for points
			this.graphics.lineStyle(1,0x444444);			
			this.graphics.moveTo(0, undoTField.y+undoTField.height+Y_PADDING);
			this.graphics.lineTo(WIDTH, undoTField.y+undoTField.height+Y_PADDING);
			this.graphics.moveTo(0, undoTField.y+undoTField.height+Y_PADDING+2);
			this.graphics.lineTo(WIDTH, undoTField.y+undoTField.height+Y_PADDING+2);
			
			
			// draw points title
			pointsTField = new TextField ();
			pointsTField.selectable = false;
			pointsTField.defaultTextFormat = new TextFormat ("arial", 20, 0x444444, null, null, null, null, null, "center");
			pointsTField.text = "points";
			pointsTField.width = WIDTH;
			pointsTField.height = 28;
			pointsTField.y = redoTField.y+redoTField.height+Y_PADDING*2;
			this.addChild(pointsTField);
			
			// draw buttons
			if (!hide_pen)
			{
				drawPenButton();
				penb.x = X_PADDING;
				penb.y = pointsTField.y + pointsTField.height + Y_PADDING;
				penTField = new TextField();
				penTField.selectable = false;
				penTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
				penTField.text = "pen";
				penTField.autoSize = "left";
				penTField.x = penb.x + (penb.width - penTField.width)/2;
				penTField.y = penb.y + penb.height;// + PADDING;
				this.addChild(penTField);
			}
			if (!hide_drag)
			{
				drawDragButton();
				dragb.x = WIDTH - BUTTON_WIDTH - X_PADDING;
				dragb.y = pointsTField.y + pointsTField.height + Y_PADDING;
				dragTField = new TextField();
				dragTField.selectable = false;
				dragTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
				dragTField.text = "drag";
				dragTField.autoSize = "left";
				dragTField.x = dragb.x + (dragb.width - dragTField.width)/2;
				dragTField.y = dragb.y + dragb.height;// + PADDING;
				this.addChild(dragTField);
			}
			
			if (!hide_delete)
			{	
				drawDeleteButton();
				deleteb.x = X_PADDING;
				deleteb.y = pointsTField.y + pointsTField.height + BUTTON_WIDTH + undoTField.height + Y_PADDING*2;
				deleteTField = new TextField();
				deleteTField.selectable = false;
				deleteTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
				deleteTField.text = "delete";
				deleteTField.autoSize = "left";
				deleteTField.x = deleteb.x + (deleteb.width - deleteTField.width)/2;
				deleteTField.y = deleteb.y + deleteb.height;// + PADDING;
				this.addChild(deleteTField);
			}
			if (!hide_pin)
			{	
				drawPinButton();
				pinb.x = WIDTH - BUTTON_WIDTH - X_PADDING;
				pinb.y = pointsTField.y + pointsTField.height + BUTTON_WIDTH + undoTField.height + Y_PADDING*2;
				pinTField = new TextField();
				pinTField.selectable = false;
				pinTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
				pinTField.text = "pin";
				pinTField.autoSize = "left";
				pinTField.x = pinb.x + (pinb.width - pinTField.width)/2;
				pinTField.y = pinb.y + pinb.height;// + PADDING;
				this.addChild(pinTField);
				
			}
			var segmentY:Number = pointsTField.y + pointsTField.height+Y_PADDING*4+BUTTON_WIDTH*2+undoTField.height*2;			
			this.graphics.moveTo(0, segmentY);
			this.graphics.lineTo(WIDTH, segmentY);
			this.graphics.moveTo(0, segmentY+2);
			this.graphics.lineTo(WIDTH, segmentY+2);
			
			// draw segments title
			segmentsTField = new TextField ();
			segmentsTField.selectable = false;
			segmentsTField.defaultTextFormat = new TextFormat ("arial", 20, 0x444444, null, null, null, null, null, "center");
			segmentsTField.text = "line segments";
			segmentsTField.width = WIDTH;
			segmentsTField.height = 28;
			segmentsTField.y = segmentY+Y_PADDING;
			this.addChild(segmentsTField);
			
			
			if (!hide_parallel)
			{					
				drawParallelButton();
				parallelb.x = X_PADDING;
				parallelb.y = segmentsTField.y+segmentsTField.height+Y_PADDING+Y_PADDING;
				parallelTField = new TextField();
				parallelTField.selectable = false;
				parallelTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
				parallelTField.text = "parallel";
				parallelTField.autoSize = "left";
				parallelTField.x = parallelb.x + (parallelb.width - parallelTField.width)/2;
				parallelTField.y = parallelb.y + parallelb.height;// + PADDING;
				this.addChild(parallelTField);
			}
			if (!hide_length)
			{	
				drawLengthButton();
				lengthb.x = WIDTH - lengthb.width - X_PADDING;
				lengthb.y = segmentsTField.y+segmentsTField.height+Y_PADDING+Y_PADDING;
				lengthTField = new TextField();
				lengthTField.selectable = false;
				lengthTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
				lengthTField.text = "congruent";
				lengthTField.autoSize = "left";
				lengthTField.x = lengthb.x + (lengthb.width - lengthTField.width)/2;
				lengthTField.y = lengthb.y + lengthb.height;// + PADDING;
				this.addChild(lengthTField);
			}
			var angleY:Number = segmentsTField.y + segmentsTField.height+Y_PADDING*3+BUTTON_WIDTH+undoTField.height*1;
			this.graphics.moveTo(0, angleY+Y_PADDING);
			this.graphics.lineTo(WIDTH, angleY+Y_PADDING);
			this.graphics.moveTo(0, angleY+2);
			this.graphics.lineTo(WIDTH, angleY+2);
				
			// draw angles title
			anglesTField = new TextField ();
			anglesTField.selectable = false;
			anglesTField.defaultTextFormat = new TextFormat ("arial", 20, 0x444444, null, null, null, null, null, "center");
			anglesTField.text = "angles";
			anglesTField.width = WIDTH;
			anglesTField.height = 28;
			anglesTField.y = angleY+Y_PADDING;
			this.addChild(anglesTField);	
			
			if (!hide_angle)
			{	
				drawAngleButton();
				angleb.x = X_PADDING;
				angleb.y = anglesTField.y+anglesTField.height+Y_PADDING;
				angleTField = new TextField();
				angleTField.selectable = false;
				angleTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
				angleTField.text = "congruent";
				angleTField.autoSize = "left";
				angleTField.x = angleb.x + (angleb.width - angleTField.width)/2;
				angleTField.y = angleb.y + angleb.height;// + PADDING;
				this.addChild(angleTField);
			}
			if (!hide_right)
			{
				drawRightButton();
				rightb.x =  WIDTH - rightb.width - X_PADDING;
				rightb.y = anglesTField.y+anglesTField.height+Y_PADDING;
				rightTField = new TextField();
				rightTField.selectable = false;
				rightTField.defaultTextFormat = new TextFormat("arial", 20, DEFAULT_TEXT_COLOR);
				rightTField.text = "right";
				rightTField.autoSize = "left";
				rightTField.x = rightb.x + (rightb.width - rightTField.width)/2;
				rightTField.y = rightb.y + rightb.height;// + PADDING;
				this.addChild(rightTField);
			}
			
			// overoutline
			overOutline = new Shape();
			overOutline.graphics.lineStyle(2,0x00000);
			overOutline.graphics.drawRect(0, 0, 0, 0);
			this.addChild(overOutline);
			
			this.addEventListener(Event.REMOVED, handleRemoved);
			
		}
		/******************* INTERACTIVITY **************************/
		/// for the state buttons
		private function handleOverButton_state (event:MouseEvent):void
		{
			if (enabled)
			{
				if (overOutline == null)
				{
					overOutline = new Shape();
					this.addChild(overOutline);
				} else 
				{
					overOutline.graphics.clear();
				}
				overOutline.graphics.lineStyle(2,0x00000);
				overOutline.graphics.drawRect(0, 0, event.currentTarget.width, event.currentTarget.height);
				overOutline.x = event.currentTarget.x;
				overOutline.y = event.currentTarget.y;
				// add a click handler
				event.currentTarget.addEventListener (MouseEvent.CLICK, handleClickButton_state);
			}
		}
		private function handleClickButton_state (event:MouseEvent):void
		{
			
			if (true)
			{
				// call to parent function
				GeometryGameItem(parent).processCommand(event.currentTarget.name, "initiate", this);
			}
		}
		
		/// for the tool buttons
		private function handleOverButton (event:MouseEvent):void
		{
			if (enabled)
			{
				// create outline if not made yet
				if (overOutline == null)
				{
					overOutline = new Shape();
					this.addChild(overOutline);
				} else
				{
					overOutline.graphics.clear();
				}			
				overOutline.graphics.lineStyle(2,0x00000);
				overOutline.graphics.drawRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH);
				
				overOutline.x = event.currentTarget.x;
				overOutline.y = event.currentTarget.y;
				// add a click handler
				event.currentTarget.addEventListener (MouseEvent.CLICK, handleClickButton);
			}
		}
		private function handleClickButton (event:MouseEvent):void
		{
			//if (selectedButton != event.currentTarget)
			//{
				
				if (selectedOutline == null)
				{
					drawSelectedOutline();
				}
				// update references
				selectedOutline.x = event.currentTarget.x;
				selectedOutline.y = event.currentTarget.y;
				selectedButton = Sprite(event.currentTarget);
				modeName = event.currentTarget.name;
				
				// call to parent function
				GeometryGameItem(parent).processCommand("toolSelection", "in_progress", this, new Array(modeName));
			//}
		}
		/** This function is strictly called from another class, does the work of the handleClickButton, but needs to find the right button */
		public function shiftModes(modeName:String):void
		{
			if (selectedOutline == null)
			{
				drawSelectedOutline();
			}
			var valid:Boolean = true;
			switch(modeName)
			{
				case "pen":
					if (hide_pen) {valid=false;}
					else {selectedButton = penb;}
					break;
				case "drag":
					if (hide_drag) {valid=false;}
					else {selectedButton = dragb;}
					break;
				case "pin":
					if (hide_pin) {valid=false;}
					else {selectedButton = pinb;}
					break;
				case "delete":
					if (hide_delete) {valid=false;}
					else {selectedButton = deleteb;}
					break;
				case "parallel":
					if (hide_parallel) {valid=false;}
					else {selectedButton = parallelb;}
					break;
				case "length":
					if (hide_length) {valid=false;}
					else {selectedButton = lengthb;}
					break;
				case "angle":
					if (hide_angle) {valid=false;}
					else {selectedButton = angleb;}
					break;
				case "right":
					if (hide_right) {valid=false;}
					else {selectedButton = rightb;}
					break;
				default:
					trace("not a valid button to shift into mode");
					return;
			}
			if (valid)
			{
				// update references
				overOutline.x = selectedButton.x;
				overOutline.y = selectedButton.y;
				selectedOutline.x = selectedButton.x;
				selectedOutline.y = selectedButton.y;
				this.modeName = selectedButton.name;
			}
		}
		public function stateChange(cmd:String, callingObject:Object):Boolean
		{
			var b:Sprite;
			switch (cmd)
			{
				case "undo":
					b = undob;
					break;
				case "redo":
					b = redob;
					break;
				case "first":
					b = firstb;
					break;
				case "last":
					b = lastb;
					break;
				default:
					trace("Not a valid state");
					return false;
			}
			if (overOutline == null)
			{
				overOutline = new Shape();
				this.addChild(overOutline);
			} else 
			{
				overOutline.graphics.clear();
			}
			overOutline.graphics.lineStyle(2,0x00000);
			overOutline.graphics.drawRect(0, 0, b.width, b.height);
			overOutline.x = b.x;
			overOutline.y = b.y;
			return true;
		}
		/****************** SETUP BUTTONS ***************************/
		private function drawUndoButton():Sprite
		{
			if (undob == null)
			{
				undob = new Sprite();
				undob.name = "undo";
				undob.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton_state);
				this.addChild(undob);
			} else
			{
				undob.graphics.clear();
			}
			undob.graphics.lineStyle(1, 0xAA8866);
			undob.graphics.beginFill(0xFFEEBB);
			undob.graphics.drawRect(0,0,BUTTON_WIDTH/2, BUTTON_WIDTH/2);
			undob.graphics.endFill();
			var cursor:Shape = new Shape();
			// draw arrow
			cursor.graphics.lineStyle(1, 0x553322);
			cursor.graphics.beginFill(0xAA8844);
			cursor.graphics.moveTo(20, -10);
			cursor.graphics.lineTo(0, -10);
			cursor.graphics.lineTo(0, -20);
			cursor.graphics.lineTo(-20, 0);
			cursor.graphics.lineTo(0, 20);
			cursor.graphics.lineTo(0, 10);
			cursor.graphics.lineTo(20, 10);
			cursor.graphics.moveTo(20, -10);			
			cursor.graphics.endFill();
			cursor.x = undob.width/2;
			cursor.y = undob.height/2;
			undob.addChild(cursor);
			
			return undob;
		}
		private function drawRedoButton():Sprite
		{
			if (redob == null)
			{
				redob = new Sprite();
				redob.name = "redo";
				redob.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton_state);
				this.addChild(redob);
			} else
			{
				redob.graphics.clear();
			}
			redob.graphics.lineStyle(1, 0xAA8866);
			redob.graphics.beginFill(0xFFEEBB);
			redob.graphics.drawRect(0,0,BUTTON_WIDTH/2, BUTTON_WIDTH/2);
			redob.graphics.endFill();
			var cursor:Shape = new Shape();
			// draw arrow
			cursor.graphics.lineStyle(1, 0x553322);
			cursor.graphics.beginFill(0xAA8844);
			cursor.graphics.moveTo(20, -10);
			cursor.graphics.lineTo(0, -10);
			cursor.graphics.lineTo(0, -20);
			cursor.graphics.lineTo(-20, 0);
			cursor.graphics.lineTo(0, 20);
			cursor.graphics.lineTo(0, 10);
			cursor.graphics.lineTo(20, 10);
			cursor.graphics.moveTo(20, -10);			
			cursor.graphics.endFill();
			cursor.x = redob.width/2;
			cursor.y = redob.height/2;
			cursor.rotation = 180;
			redob.addChild(cursor);
			
			return redob;
		}
		private function drawFirstButton():Sprite
		{
			if (firstb == null)
			{
				firstb = new Sprite();
				firstb.name = "first";
				firstb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton_state);
				this.addChild(firstb);
			} else
			{
				firstb.graphics.clear();
			}
			firstb.graphics.lineStyle(1, 0xAA8866);
			firstb.graphics.beginFill(0xFFEEBB);
			firstb.graphics.drawRect(0,0,BUTTON_WIDTH/4, BUTTON_WIDTH/2);
			firstb.graphics.endFill();
			var cursor:Shape = new Shape();
			// draw arrow
			cursor.graphics.lineStyle(1, 0x553322);
			cursor.graphics.beginFill(0xAA8844);
			cursor.graphics.moveTo(10, -20);
			cursor.graphics.lineTo(-10, 0);
			cursor.graphics.lineTo(10, 20);
			cursor.graphics.lineTo(10, -20);		
			cursor.graphics.endFill();
			cursor.x = firstb.width/2;
			cursor.y = firstb.height/2;
			firstb.addChild(cursor);
			return firstb;
		}
		private function drawLastButton():Sprite
		{
			if (lastb == null)
			{
				lastb = new Sprite();
				lastb.name = "last";
				lastb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton_state);
				this.addChild(lastb);
			} else
			{
				lastb.graphics.clear();
			}
			lastb.graphics.lineStyle(1, 0xAA8866);
			lastb.graphics.beginFill(0xFFEEBB);
			lastb.graphics.drawRect(0,0,BUTTON_WIDTH/4, BUTTON_WIDTH/2);
			lastb.graphics.endFill();
			var cursor:Shape = new Shape();
			// draw arrow
			cursor.graphics.lineStyle(1, 0x553322);
			cursor.graphics.beginFill(0xAA8844);
			cursor.graphics.moveTo(10, -20);
			cursor.graphics.lineTo(-10, 0);
			cursor.graphics.lineTo(10, 20);
			cursor.graphics.lineTo(10, -20);		
			cursor.graphics.endFill();
			cursor.x = lastb.width/2;
			cursor.y = lastb.height/2;
			cursor.rotation = 180;
			lastb.addChild(cursor);
			return lastb;
		}
		
		private function drawPenButton():Sprite
		{
			var cursor:Sprite;
			if (penb == null)
			{
				penb = new Sprite();
				penb.name = "pen";
				penb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton);
				this.addChild(penb);
				cursor = new Sprite();
				cursor.mouseEnabled = false;
				penb.addChild(cursor);
				if (freePointsRemaining >= 0)
				{
					freePointsTField = new TextField();
					freePointsTField.border = true;
					freePointsTField.borderColor = 0x888888;
					freePointsTField.selectable = false;
					freePointsTField.mouseEnabled = false;
					freePointsTField.defaultTextFormat = new TextFormat("arial",18,0x444444,null,null,null,null,null,"center");
					penb.addChild(freePointsTField);
				}
			} else 
			{
				penb.graphics.clear();
				if (penb.numChildren > 1)
				{
					if (flash.utils.getQualifiedClassName(penb.getChildAt(0)) == "flash.display::Sprite")
					{
						cursor = Sprite(penb.getChildAt(0));	
						freePointsTField = TextField(penb.getChildAt(1));
					} else
					{
						cursor = Sprite(penb.getChildAt(1));	
						freePointsTField = TextField(penb.getChildAt(0));
					}						
				} else
				{
					cursor = Sprite(penb.getChildAt(0));	
				}
				cursor.graphics.clear();
			}
			var pwidth:Number = 8;
			var pheight:Number = 40;
			penb.graphics.lineStyle(1, 0xAA8866);
			penb.graphics.beginFill(0xFFEEBB);
			penb.graphics.drawRect(0,0,BUTTON_WIDTH, BUTTON_WIDTH);
			penb.graphics.endFill();
			var pointsize:Number = 60;
			cursor.x = BUTTON_WIDTH/2;
			cursor.y = BUTTON_WIDTH/2+5;
			// draw circle
			var cx:Number = 0;
			var cy:Number = 0;
			cursor.graphics.lineStyle(pwidth/4,0x888888);
			cursor.graphics.beginFill(0xFFFF00);
			//cursor.graphics.beginFill(0x888888);
			cursor.graphics.drawEllipse(cx-15,cy-15,30,30);
			cursor.graphics.endFill();
			// draw pen
			cursor.graphics.lineStyle(pwidth/8,0x444444);
			cursor.graphics.beginFill(0x888888);
			cursor.graphics.moveTo(cx,cy);
			cursor.graphics.lineTo(cx+pwidth/2,cy-pwidth);
			cursor.graphics.lineTo(cx-pwidth/2,cy-pwidth)
			cursor.graphics.lineTo(cx,cy);
			cursor.graphics.beginFill(0x8888FF);
			cursor.graphics.moveTo(cx+pwidth/2,cy-pwidth);
			cursor.graphics.lineTo(cx+pwidth/2,cy-pheight);
			cursor.graphics.lineTo(cx-pwidth/2,cy-pheight);
			cursor.graphics.lineTo(cx-pwidth/2,cy-pwidth)
			cursor.graphics.endFill();
			// handle
			cursor.graphics.beginFill(0x888888);
			cursor.graphics.drawEllipse(cx-pwidth/2,cy-pheight-pwidth/4,pwidth,pwidth/2);
			cursor.graphics.endFill();
			cursor.rotation=30;
			//penb.addChild(cursor);
			if (freePointsTField != null)
			{
				freePointsTField.text = String(freePointsRemaining);
				freePointsTField.autoSize = "left";
			}
			return penb;
		}
		private function drawDragButton():Sprite
		{
			if (dragb == null)
			{
				dragb = new Sprite();
				dragb.name = "drag";
				dragb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton);
				this.addChild(dragb);
			} else 
			{
				dragb.graphics.clear();
			}
			var pointsize:Number = 60;
			var cdenom:Number = 2;
			var adenom:Number = 8;
			dragb.graphics.lineStyle(1, 0xAA8866);
			dragb.graphics.beginFill(0xFFEEBB);
			dragb.graphics.drawRect(0,0,BUTTON_WIDTH, BUTTON_WIDTH);
			dragb.graphics.endFill();
			var cursor:Shape = new Shape();
			cursor.graphics.clear();
			// draw circle
			cursor.graphics.beginFill(POINT_COLOR);
			cursor.graphics.drawEllipse(-15,-15,30,30);
			cursor.graphics.endFill();
			
			cursor.graphics.lineStyle(2,0x000000);
			cursor.graphics.moveTo(0,-pointsize/cdenom);
			cursor.graphics.lineTo(0,pointsize/cdenom);
			cursor.graphics.moveTo(-pointsize/cdenom,0);
			cursor.graphics.lineTo(pointsize/cdenom,0);
			//arrowheads
			cursor.graphics.lineStyle(4,0x000000);
			//top
			cursor.graphics.moveTo(0,-pointsize/cdenom);
			cursor.graphics.lineTo(-pointsize/adenom,-pointsize/cdenom+pointsize/adenom);
			cursor.graphics.moveTo(0,-pointsize/cdenom);
			cursor.graphics.lineTo(pointsize/adenom,-pointsize/cdenom+pointsize/adenom);
			//bottom
			cursor.graphics.moveTo(0,pointsize/cdenom);
			cursor.graphics.lineTo(-pointsize/adenom,pointsize/cdenom-pointsize/adenom);
			cursor.graphics.moveTo(0,pointsize/cdenom);
			cursor.graphics.lineTo(pointsize/adenom,pointsize/cdenom-pointsize/adenom);
			//left
			cursor.graphics.moveTo(-pointsize/cdenom,0);
			cursor.graphics.lineTo(-pointsize/cdenom+pointsize/adenom,-pointsize/adenom);
			cursor.graphics.moveTo(-pointsize/cdenom,0);
			cursor.graphics.lineTo(-pointsize/cdenom+pointsize/adenom, pointsize/adenom);
			//right
			cursor.graphics.moveTo(pointsize/cdenom,0);
			cursor.graphics.lineTo(pointsize/cdenom-pointsize/adenom,-pointsize/adenom);
			cursor.graphics.moveTo(pointsize/cdenom,0);
			cursor.graphics.lineTo(pointsize/cdenom-pointsize/adenom, pointsize/adenom);
			
			cursor.x = dragb.width/2;
			cursor.y = dragb.height/2+5;
			dragb.addChild(cursor);
			
			return dragb;
		}
		private function drawPinButton():Sprite
		{
			if (pinb == null)
			{
				pinb = new Sprite();
				pinb.name = "pin";
				pinb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton);
				this.addChild(pinb);
			} else 
			{
				pinb.graphics.clear();
			}
			pinb.graphics.lineStyle(1, 0xAA8866);
			pinb.graphics.beginFill(0xFFEEBB);
			pinb.graphics.drawRect(0,0,BUTTON_WIDTH, BUTTON_WIDTH);
			pinb.graphics.endFill();
			var cursor:Shape = new Shape();
			cursor.graphics.clear();
			// draw circle
			cursor.graphics.beginFill(POINT_COLOR);
			cursor.graphics.drawEllipse(-15,-15,30,30);
			cursor.graphics.endFill();
			// draw pin
			var twidth:Number = 6;
			var theight:Number = 30;
			var hwidth:Number = 16;
			var hheight:Number = 16;
			cursor.graphics.lineStyle(twidth/8,0x666666);
			cursor.graphics.beginFill(0xCCCCCC);
			cursor.graphics.moveTo(0,4);
			cursor.graphics.lineTo(twidth/2,4-twidth);
			cursor.graphics.lineTo(twidth/2,4-theight);
			cursor.graphics.lineTo(-twidth/2,4-theight);
			cursor.graphics.lineTo(-twidth/2,4-twidth)
			cursor.graphics.lineTo(0,4);
			cursor.graphics.endFill();
			// handle
			cursor.graphics.beginFill(0xFFFFFF);
			cursor.graphics.drawEllipse(-hwidth/2,4-theight,hwidth,hwidth/2);
			cursor.graphics.endFill();
			
			cursor.x = pinb.width/2;
			cursor.y = pinb.height/2+5;
			pinb.addChild(cursor);
			return pinb;
		}
		private function drawDeleteButton():Sprite
		{
			if (deleteb == null)
			{
				deleteb = new Sprite();
				deleteb.name = "delete";
				deleteb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton);
				this.addChild(deleteb);
			} else 
			{
				deleteb.graphics.clear();
			}
			deleteb.graphics.lineStyle(1, 0xAA8866);
			deleteb.graphics.beginFill(0xFFEEBB);
			deleteb.graphics.drawRect(0,0,BUTTON_WIDTH, BUTTON_WIDTH);
			deleteb.graphics.endFill();
			var cursor:Shape = new Shape();
			var erasersize:Number = 60;
			cursor.graphics.clear();
			// draw circle
			cursor.graphics.beginFill(POINT_COLOR);
			cursor.graphics.drawEllipse(-15,-15,30,30);
			cursor.graphics.endFill();
			//cursor.graphics.beginFill(0xFFFFFF, .5)
			cursor.graphics.drawEllipse(-erasersize/2, -erasersize/2, erasersize, erasersize);
			//cursor.graphics.endFill();
			cursor.graphics.lineStyle(2,0x000000);
			cursor.graphics.moveTo(-erasersize/2*Math.sqrt(2)/2,-erasersize/2*Math.sqrt(2)/2);
			cursor.graphics.lineTo(erasersize/2*Math.sqrt(2)/2,erasersize/2*Math.sqrt(2)/2);
			cursor.graphics.moveTo(erasersize/2*Math.sqrt(2)/2,-erasersize/2*Math.sqrt(2)/2);
			cursor.graphics.lineTo(-erasersize/2*Math.sqrt(2)/2,erasersize/2*Math.sqrt(2)/2);
			
			cursor.x = deleteb.width/2;
			cursor.y = deleteb.height/2+5;
			deleteb.addChild(cursor);
			return deleteb;
		}
		private function drawParallelButton():Sprite
		{
			if (parallelb == null)
			{
				parallelb = new Sprite();
				parallelb.name = "parallel";
				parallelb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton);
				this.addChild(parallelb);
			} else 
			{
				parallelb.graphics.clear();
			}
			parallelb.graphics.lineStyle(1, 0xAA8866);
			parallelb.graphics.beginFill(0xFFEEBB);
			parallelb.graphics.drawRect(0,0,BUTTON_WIDTH, BUTTON_WIDTH);
			parallelb.graphics.endFill();
			var cursor:Shape = new Shape();
			var pointsize:Number = 60;
			// draw the "segments"
			cursor.graphics.lineStyle(4,0x888888);
			cursor.graphics.moveTo(-BUTTON_WIDTH/2+2, 10);
			cursor.graphics.lineTo(10, -BUTTON_WIDTH/2+2);
			cursor.graphics.moveTo(-10, BUTTON_WIDTH/2-2);
			cursor.graphics.lineTo(BUTTON_WIDTH/2-2, -10);
			cursor.x = parallelb.width/2;
			cursor.y = parallelb.height/2;
			parallelb.addChild(cursor);
			// draw the "magnets"
			var m1:Shape = new Shape();
			m1.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m1.graphics.beginFill(0xCCCCCC);
			m1.graphics.drawRect(-5,-20,10,40);
			m1.graphics.endFill();
			m1.x = parallelb.width/2-14; m1.y = parallelb.height/2-14; m1.rotation = 45;
			
			var m2:Shape = new Shape();
			m2.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m2.graphics.beginFill(0xCCCCCC);
			m2.graphics.drawRect(-5,-20,10,40);
			m2.graphics.endFill();
			m2.x = parallelb.width/2+14; m2.y = parallelb.height/2+14; m2.rotation = 45;
			
			var d:Number = MathUtilities.distance(m1.x, m1.y, m2.x, m2.y);
			
			var arm:Shape = new Shape();
			arm.graphics.lineStyle(1,0x888888);
			arm.graphics.beginFill(0xDDDDDD);
			arm.graphics.drawRect(-2, -d/2, 4, d);
			arm.graphics.endFill();
			arm.graphics.moveTo(0,-d/2);
			arm.graphics.lineTo(0,d/2);
			arm.x = parallelb.width/2; arm.y = parallelb.height/2; arm.rotation = 135;
			parallelb.addChild(arm);
			parallelb.addChild(m1);
			parallelb.addChild(m2);
			
			return parallelb;
		}
		
		private function drawLengthButton():Sprite
		{
			if (lengthb == null)
			{
				lengthb = new Sprite();
				lengthb.name = "length";
				lengthb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton);
				this.addChild(lengthb);
			} else 
			{
				lengthb.graphics.clear();
			}
			lengthb.graphics.lineStyle(1, 0xAA8866);
			lengthb.graphics.beginFill(0xFFEEBB);
			lengthb.graphics.drawRect(0,0,BUTTON_WIDTH, BUTTON_WIDTH);
			lengthb.graphics.endFill();
			var cursor:Shape = new Shape();
			var pointsize:Number = 60;
			// draw the "segments"
			cursor.graphics.lineStyle(4,0x888888);
			cursor.graphics.moveTo(-BUTTON_WIDTH/2+10, BUTTON_WIDTH/2-10);
			cursor.graphics.lineTo(-10, -BUTTON_WIDTH/2+10);
			cursor.graphics.moveTo(10, -BUTTON_WIDTH/2+10);
			cursor.graphics.lineTo(BUTTON_WIDTH/2-10, BUTTON_WIDTH/2-10);
			cursor.x = lengthb.width/2;
			cursor.y = lengthb.height/2;
			lengthb.addChild(cursor);
			// draw the "magnets"
			var d:Number = MathUtilities.distance(-BUTTON_WIDTH/2, BUTTON_WIDTH/2-10, -10, -BUTTON_WIDTH/2+10);
			var m1:Shape = new Shape();
			m1.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m1.graphics.beginFill(0xCCCCCC);
			m1.graphics.drawRect(-5,d/2-2,10,4);
			m1.graphics.endFill();
			m1.graphics.beginFill(0xCCCCCC);
			m1.graphics.drawRect(-5,-d/2+2,10,4);
			m1.graphics.endFill();
			m1.x = lengthb.width/2-19; m1.y = lengthb.height/2-2; m1.rotation = 20;
			
			var m2:Shape = new Shape();
			m2.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m2.graphics.beginFill(0xCCCCCC);
			m2.graphics.drawRect(-5,d/2-2,10,4);
			m2.graphics.endFill();
			m2.graphics.beginFill(0xCCCCCC);
			m2.graphics.drawRect(-5,-d/2+2,10,4);
			m2.graphics.endFill();
			m2.x = lengthb.width/2+19; m2.y = lengthb.height/2-2; m2.rotation = -20;
			
			lengthb.addChild(m1);
			lengthb.addChild(m2);
			
			return lengthb;
		}
		
		private function drawAngleButton():Sprite
		{
			if (angleb == null)
			{
				angleb = new Sprite();
				angleb.name = "angle";
				angleb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton);
				this.addChild(angleb);
			} else 
			{
				angleb.graphics.clear();
			}
			angleb.graphics.lineStyle(1, 0xAA8866);
			angleb.graphics.beginFill(0xFFEEBB);
			angleb.graphics.drawRect(0,0,BUTTON_WIDTH, BUTTON_WIDTH);
			angleb.graphics.endFill();
			var cursor:Shape = new Shape();
			var pointsize:Number = 60;
			// draw the "segments"
			cursor.graphics.lineStyle(4,0x888888);
			cursor.graphics.moveTo(-25, -20);
			cursor.graphics.lineTo(-BUTTON_WIDTH/2+10, BUTTON_WIDTH/2-10);
			cursor.graphics.lineTo(20, 25);
			cursor.graphics.moveTo(-20, -25);
			cursor.graphics.lineTo(BUTTON_WIDTH/2-10, -BUTTON_WIDTH/2+10);
			cursor.graphics.lineTo(25, 20);
			cursor.x = angleb.width/2;
			cursor.y = angleb.height/2;
			angleb.addChild(cursor);
			// draw the "magnets"
			var m1a:Shape= new Shape(), m1b:Shape= new Shape(), c1:Shape = new Shape();
			m1a.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m1a.graphics.beginFill(0xCCCCCC);
			m1a.graphics.drawRect(-3,0,6,-30);
			m1a.graphics.endFill();
			m1a.x = angleb.width/2-BUTTON_WIDTH/2+10; m1a.y = angleb.height/2+BUTTON_WIDTH/2-10;
			m1a.rotation = 6;
			
			m1b.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m1b.graphics.beginFill(0xCCCCCC);
			m1b.graphics.drawRect(-3,0,6,-30);
			m1b.graphics.endFill();
			m1b.x = angleb.width/2-BUTTON_WIDTH/2+10; m1b.y = angleb.height/2+BUTTON_WIDTH/2-10;
			m1b.rotation = 84;
			
			c1.graphics.beginFill(0xCCCCCC);
			c1.graphics.drawEllipse(-4,-4, 8, 8);
			c1.graphics.endFill();
			c1.x = angleb.width/2-BUTTON_WIDTH/2+10; c1.y = angleb.height/2+BUTTON_WIDTH/2-10;
			
			angleb.addChild(m1a); angleb.addChild(m1b); angleb.addChild(c1);
			
			var m2a:Shape= new Shape(), m2b:Shape= new Shape(), c2:Shape = new Shape();
			m2a.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m2a.graphics.beginFill(0xCCCCCC);
			m2a.graphics.drawRect(-3,0,6,30);
			m2a.graphics.endFill();
			m2a.x = angleb.width/2+BUTTON_WIDTH/2-10; m2a.y = angleb.height/2-BUTTON_WIDTH/2+10;
			m2a.rotation = 6;
			
			m2b.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m2b.graphics.beginFill(0xCCCCCC);
			m2b.graphics.drawRect(-3,0,6,30);
			m2b.graphics.endFill();
			m2b.x = angleb.width/2+BUTTON_WIDTH/2-10; m2b.y = angleb.height/2-BUTTON_WIDTH/2+10;
			m2b.rotation = 84;
			
			c2.graphics.beginFill(0xCCCCCC);
			c2.graphics.drawEllipse(-4,-4, 8, 8);
			c2.graphics.endFill();
			c2.x = angleb.width/2+BUTTON_WIDTH/2-10; c2.y = angleb.height/2-BUTTON_WIDTH/2+10;
			
			angleb.addChild(m2a); angleb.addChild(m2b); angleb.addChild(c2);
			
			return angleb;
		}
		
		private function drawRightButton():Sprite
		{
			if (rightb == null)
			{
				rightb = new Sprite();
				rightb.name = "right";
				rightb.addEventListener(MouseEvent.MOUSE_OVER, handleOverButton);
				this.addChild(rightb);
			} else 
			{
				rightb.graphics.clear();
			}
			rightb.graphics.lineStyle(1, 0xAA8866);
			rightb.graphics.beginFill(0xFFEEBB);
			rightb.graphics.drawRect(0,0,BUTTON_WIDTH, BUTTON_WIDTH);
			rightb.graphics.endFill();
			var cursor:Shape = new Shape();
			var pointsize:Number = 60;
			// draw the "segments"
			cursor.graphics.lineStyle(4,0x888888);
			cursor.graphics.moveTo(-BUTTON_WIDTH/2+20, -BUTTON_WIDTH/2+15);
			cursor.graphics.lineTo(-BUTTON_WIDTH/2+20, BUTTON_WIDTH/2-20);
			cursor.graphics.lineTo(BUTTON_WIDTH/2-15, BUTTON_WIDTH/2-20);
			//cursor.graphics.lineStyle(2,0x8888FF);
			//cursor.graphics.moveTo(-BUTTON_WIDTH/2+20, BUTTON_WIDTH/2-40);
			//cursor.graphics.lineTo(-BUTTON_WIDTH/2+40, BUTTON_WIDTH/2-40);
			//cursor.graphics.lineTo(-BUTTON_WIDTH/2+40, BUTTON_WIDTH/2-20);
			
			cursor.x = rightb.width/2;
			cursor.y = rightb.height/2;
			rightb.addChild(cursor);
			// draw the "magnets"
			var m1a:Shape= new Shape(), m1b:Shape= new Shape(), c1:Shape = new Shape();
			m1a.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m1a.graphics.beginFill(0xCCCCCC);
			m1a.graphics.drawRect(-3,0,6,-30);
			m1a.graphics.endFill();
			m1a.x = rightb.width/2-BUTTON_WIDTH/2+20; m1a.y = rightb.height/2+BUTTON_WIDTH/2-20;
			m1a.rotation = 0;
			
			m1b.graphics.lineStyle(1,TOOL_OUTLINE_COLOR);
			m1b.graphics.beginFill(0xCCCCCC);
			m1b.graphics.drawRect(-3,0,6,-30);
			m1b.graphics.endFill();
			m1b.x = rightb.width/2-BUTTON_WIDTH/2+20; m1b.y = rightb.height/2+BUTTON_WIDTH/2-20;
			m1b.rotation = 90;
			
			c1.graphics.beginFill(0xCCCCCC);
			c1.graphics.drawEllipse(-4,-4, 8, 8);
			c1.graphics.endFill();
			c1.x = rightb.width/2-BUTTON_WIDTH/2+20; c1.y = rightb.height/2+BUTTON_WIDTH/2-20;
			
			rightb.addChild(m1a); rightb.addChild(m1b); rightb.addChild(c1);
			
			
			return rightb;
		}
		
		private function drawSelectedOutline():void
		{
			if (selectedOutline == null)
			{
				selectedOutline = new Shape();
				this.addChild(selectedOutline);
			}
			//outside violet
			//selectedOutline.graphics.lineStyle(1,0x000000);
			selectedOutline.graphics.lineStyle(2,0xFF44CC);
			selectedOutline.graphics.drawRect(-2, -2, BUTTON_WIDTH+4, BUTTON_WIDTH+4);
			// center yellow
			//selectedOutline.graphics.lineStyle(2,0xFFFF44);
			selectedOutline.graphics.lineStyle(2,0xFFFF00);
			selectedOutline.graphics.drawRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH);
			//inside black
			//selectedOutline.graphics.lineStyle(1,0x000000);
			selectedOutline.graphics.lineStyle(2,0xFF44CC);
			selectedOutline.graphics.drawRect(2, 2, BUTTON_WIDTH-4, BUTTON_WIDTH-4);			
		
		}
		
		/////////// INTERACTIVITY WITH GAME MENU, COMPLETES THIS 
		/** Highlights game menu tab, then allows clicking */
		private function handleMouseOverGame(event:MouseEvent):void
		{
			if (enabled)
			{
				gameBack.removeEventListener(MouseEvent.MOUSE_OVER, handleMouseOverGame);
				gameBack.graphics.clear();
				gameBack.graphics.lineStyle(1,0x000000);
				gameBack.graphics.beginFill(0x6666CC);
				gameBack.graphics.drawRect(0,0,WIDTH/2, TITLE_HEIGHT*2/3);
				gameBack.graphics.endFill();
				gameTField.defaultTextFormat = new TextFormat ("arial", 22, 0xFFFFFF, null, null, null, null, null, "center");
				gameTField.text = "Shapes";
				gameBack.addEventListener(MouseEvent.MOUSE_OUT, handleMouseOutGame);
				gameBack.addEventListener(MouseEvent.CLICK, handleMouseClickGame);
			}
		}
		/** Un-Highlights game menu tab, then dis-allows clicking */
		private function handleMouseOutGame(event:MouseEvent):void
		{
			gameBack.removeEventListener(MouseEvent.MOUSE_OUT, handleMouseOutGame);
			gameBack.removeEventListener(MouseEvent.CLICK, handleMouseClickGame);
			gameBack.graphics.clear();
			gameBack.graphics.lineStyle(1,0x000000);
			gameBack.graphics.beginFill(0x6666AA);
			gameBack.graphics.drawRect(0,0,WIDTH/2, TITLE_HEIGHT*2/3);
			gameBack.graphics.endFill();
			gameTField.defaultTextFormat = new TextFormat ("arial", 22, 0xAAAAAA, null, null, null, null, null, "center");
			gameTField.text = "Shapes";
			gameBack.addEventListener(MouseEvent.MOUSE_OVER, handleMouseOverGame);
			
		}
		/** Removes listeners and dispatches a COMPLETE event */
		private function handleMouseClickGame(event:MouseEvent):void
		{
			//this.dispatchEvent(new Event(Event.COMPLETE));
			GeometryGameItem(parent).processCommand("toolMenu", "complete", this);		
			
		}
		private function handleRemoved(event:Event):void
		{
			this.removeEventListener(Event.REMOVED, handleRemoved);
			gameBack.removeEventListener(MouseEvent.MOUSE_OUT, handleMouseOutGame);
			gameBack.removeEventListener(MouseEvent.CLICK, handleMouseClickGame);
		}
	}
}